package org.example.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.domain.Dict;
import org.example.dto.DictQueryDTO;
import org.example.result.PageResult;
import org.example.service.DictService;
import org.example.mapper.DictMapper;
import org.example.vo.DictVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wangmengyi_1
 * @description 针对表【sys_dict】的数据库操作Service实现
 * @createDate 2024-05-29 11:08:02
 */
@Service
public class DictServiceImpl implements DictService {
    @Autowired
    DictMapper dictMapper;

    @Override
    public boolean save(DictQueryDTO dictQueryDTO) {
        return dictMapper.save(dictQueryDTO);
    }

    @Override
    public boolean update(DictQueryDTO dictQueryDTO) {
        return dictMapper.update(dictQueryDTO);
    }

    @Override
    public boolean removeById(Integer id) {
        return dictMapper.removeById(id);
    }

    @Override
    public PageResult list(DictQueryDTO dictQueryDTO) {
        PageHelper.startPage(dictQueryDTO.getPageNum(), dictQueryDTO.getPageSize());
        Page<DictVo> page = dictMapper.list(dictQueryDTO);;
        return PageResult.builder()
                .recodes(page)
                .total(page.getTotal())
                .build();
    }

    @Override
    public PageResult listAll(DictQueryDTO dictQueryDTO) {
        PageHelper.startPage(dictQueryDTO.getPageNum(), dictQueryDTO.getPageSize());
        Page<Dict> page = dictMapper.listAll(dictQueryDTO);
        return PageResult.builder()
                .recodes(page)
                .total(page.getTotal())
                .build();
    }
}




